package com.basic.controller;

import com.area.entity.Brand;
import com.area.service.IBrandService;
import com.code.domain.CommonResult;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
@Slf4j
@CrossOrigin
@ApiOperation(value = "基础数据",notes = "基础数据")
@RequestMapping(value = "/basic/brand")
public class BasicController {

    @Autowired
    private IBrandService brandService;

    @ApiOperation(value = "跳转到首页",notes = "跳转到首页")
    @RequestMapping(value = {"/","/index"})
    public String toIndex(Model model,HttpServletRequest request){
        model.addAttribute("msg","欢迎进入首页");
        return "index/index";
    }

    @ApiOperation(value = "跳转到登录界面",notes = "跳转到登录界面")
    @RequestMapping(value = "/toLogin")
    public String toLogin(Model model){
        model.addAttribute("msg","欢迎进入登录界面");
        return "login/login";
    }

    @ApiOperation(value="跳转到区块界面",notes = "跳转到区块界面")
    @RequestMapping(value = "/toArea")
    public String toArea(Model model){
        model.addAttribute("msg","欢迎进入区块界面");
        return "area/area";
    }

    @ApiOperation(value="跳转到用户界面",notes = "跳转到用户界面")
    @RequestMapping(value = "/toUser")
    public String toUser(Model model){
        model.addAttribute("msg","欢迎进入用户界面");
        return "user/user";
    }

    @ApiOperation(value="跳转到错误界面",notes = "跳转到错误界面")
    @RequestMapping(value = "/toError")
    public String toError(Model model){
        model.addAttribute("msg","欢迎进入错误界面");
        return "error/error";
    }
    @ApiOperation(value="跳转到错误界面",notes = "跳转到错误界面")
    @RequestMapping(value = "/toUnauthorized")
    public String toUnauthorized(Model model){
        model.addAttribute("msg","未授权");
        return "403/403";
    }


    @ApiOperation(value = "查询品牌列表", notes = "查询品牌列表")
    @RequestMapping(value = "/queryBasicBrandAll")
    public @ResponseBody CommonResult queryBasicBrandAll(Brand brand,
                                                         HttpServletRequest request,
                                                         HttpServletResponse response){
        List<Brand> brandList = brandService.queryBrandAll(brand);
        return new CommonResult(0,"操作成功",brandList.size(),brandList);
    }


}
